<%@page import="QRCG.Util"%>
<%@page import="QRCG.CookieManager"%>
<%@page import="QRCG.LoginServe"%>
<div id="wrapper">
	<div id="header-wrapper"></div>
</div>


<div id="header">
	<div id="logo">
		<img src="images/InspectorTransparent.png" id="logo" /><a
			href="UserMainPage.jsp">QR MARKS THE SPOT</a>
	</div>
	<%
		String pageName = request.getRequestURL().toString();
		String[] elements = pageName.split("/");
		pageName = elements[elements.length - 1];
		
		String nickname = CookieManager.getSessionCookieValue(request, "nickname");
		boolean success = Util.hasTextContent(nickname);

		if (!success && session.getAttribute("nickname") == null) {
	%>
	<form name="login" method="post" action="LoginServe">
		<div id="login">
			<table>
				<tr>
					<td class="login-label">Nickname:</td>
					<td><input type="text" name="nickname" class="login-text" /></td>
				</tr>
				<tr>
					<td class="login-label">Password:</td>
					<td><input type="password" name="password" class="login-text" /></td>
					<td><input type="submit" value="Login" id="login-button" /></td>
				</tr>
			</table>
		</div>
	</form>
	<div id="forgotPassword">
		<a href="ForgotPassword.jsp">Forgot Password?</a>
	</div>
</div>
<!-- END HEADER -->

<%
	if (!pageName.equals("SignUp.jsp") && !pageName.equals("ForgotPassword.jsp")) {
			if (session.getAttribute("error_msg") != null) {
%>
<div class="information-text">
	<table align="center">
		<tr>
			<td><font color=#D14836>${error_msg}</font></td>
		</tr>
	</table>
</div>

<%
	}
%>
<div id="signup-remind" align="center">
	<div>
		You are not a member yet? Go <a href="SignUp.jsp"
			onclick="return loadIframe('ifrm', this.href)">Sign Up</a> now!
	</div>
</div>
<%
	} else {
			if ((session.getAttribute("error_msg") != null)
					&& (session.getAttribute("error_msg") != LoginServe.LOGIN_FAILED_MISMATCH)
					&& (session.getAttribute("error_msg") != LoginServe.LOGIN_FAILED_FILLBLANKS)) {
%>
<div class="information-text">
	<table align="center">
		<tr>
			<td><font color=#D14836>${error_msg}</font></td>
		</tr>
	</table>
</div>

<%
	}
		}

	}

	else {
		String name = "";
		if(success) {
			name = nickname;
		}
		else {
			name = (String) session.getAttribute("nickname");
		}
		session.setAttribute("nickname", name);
		session.setAttribute("error_msg", null); //for log in error
%>
<div id="username">
	<div>
		Welcome
		<%=name%></div>
	<div>
		<a href="Profile.jsp" onclick="return loadIframe('ifrm', this.href)">My
			Profile</a> <a href="index.jsp?logout=true"
			onclick="return loadIframe('ifrm', this.href)">Logout</a>
	</div>
</div>

<!-- END HEADER -->
</div>

<div id="menu">
	<ul>
		<li
			<%if (pageName.equals("UserMainPage.jsp") || pageName.equals("index.jsp")) {%>
			class="current_page_item" <%}%>><a href="UserMainPage.jsp"
			onclick="return loadIframe('ifrm', this.href)">Main Page</a></li>

		<li <%if (pageName.equals("CreateNewGame.jsp")) {%>
			class="current_page_item" <%}%>><a href="CreateNewGame.jsp"
			onclick="return loadIframe('ifrm', this.href)">Create A Game</a></li>

		<li <%if (pageName.equals("ViewGames.jsp")) {%>
			class="current_page_item" <%}%>><a href="ViewGames.jsp"
			onclick="return loadIframe('ifrm', this.href)">View - Search Games</a></li>
		
		<li <%if (pageName.equals("Statistics.jsp")) {%>
			class="current_page_item" <%}%>><a href="Statistics.jsp"
			onclick="return loadIframe('ifrm', this.href)">Statistics</a></li>
		
		<li <%if (pageName.equals("ContactAdmin.jsp")) {%>
			class="current_page_item" <%}%>><a href="ContactAdmin.jsp"
			onclick="return loadIframe('ifrm', this.href)">Contact To Admin</a></li>

		<li <%if (pageName.equals("Forum.jsp")) {%> class="current_page_item"
			<%}%>><a href="Forum.jsp"
			onclick="return loadIframe('ifrm', this.href)">View Forums</a></li>
	</ul>
</div>


<%
	}
%>
